// pages/operation/classRecord/classMakeUp/index.js
import { LessonModel } from "../../../../api/api-work/lesson.js";
const lessonModel = new LessonModel()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNum: 1,
    total: 0,
    tableDatas: [],
    triggered: false,
    loadStatus: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    await this.getLessonList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  // 获取补课课程
  async getLessonList() {
    lessonModel.getLessonApi({ pageNum: this.data.pageNum, pageSize: 15, state: "0" }).then(res => {
      let rows = this.data.tableDatas;
      rows.push(...res.rows);
      this.setData({
        tableDatas: rows,
        total: res.total
      })
      if (this.data.total == 0) {
        this.setData({
          loadStatus: ""
        })
      }
      else if (this.data.tableDatas.length < this.data.total) {
        this.setData({
          loadStatus: "loadmore"
        })
      }
      else {
        this.setData({
          loadStatus: "nomore"
        })
      }
    })
  },
  getMoreDatas() {
    if (this.data.loadStatus === "nomore") {
      return;
    }
    this.setData({
      pageNum: this.data.pageNum + 1,
      loadStatus: "loading"
    })
    this.getLessonList()
  },
  refreshMoreDatas() {
    this.setData({
      triggered: false,
      pageNum: 1,
      tableDatas: []
    })
    this.getLessonList()
  },
  // 选择课程
  chooseMissedStudent(e) {
    const param = JSON.stringify(e.currentTarget.dataset.query)
    wx.navigateTo({
      url: `/pages/operation/classRecord/classMakeupStudent/index?param=${param}`,
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})